import { removeById } from '@/api/system/message'
import { findComponentByName } from '@/utils'

export default {
  methods: {
    /**
     * 消息中心-点击消息跳转
     * @param {*} message
     */
    onTapMessageTo(message) {
      const { msgUrl, messageId, type, isLook, id } = message
      if (!msgUrl) return
      switch (type) {
        case 1: {
          // 订单
          // let url = msgUrl.split("?")[0];
          const params = {
            orderNo: messageId
          }

          if (isLook === 1) {
            // 更改为已查看
            removeById(id).then(() => {
              message.isLook = 2

              if (this.$options.name === 'MessageNotice') {
                // 当前处于顶部消息栏
                this.refresh()
              } else {
                // 当前处于消息中心
                const vueEl = findComponentByName(this.$root, 'MessageNotice')
                vueEl.refresh()
              }
            })
          }

          if (this.$router.currentRoute.name !== 'outorder') {
            this.$router.push({ name: 'outorder', params: params })
          } else {
            const vueEl = findComponentByName(this.$root, 'clinicCharges')
            vueEl.onOperateRow({ id: messageId })
          }
          break
        }
      }
    }
  }
}
